package com.zm.demo.core.leetcode;

/**
 * 字符串格式化
 * Created by Administrator on 2020/1/7.
 */
public class LicenseKeyFormatting {

    public static String licenseKeyFormatting(String S, int K) {
        StringBuilder sb=new StringBuilder();
        S = S.replace("-", "");
        int j=0;
        for (int i = S.length()-1; i>=0; i--){
            sb.append(S.charAt(i));
            if ((++j) % K == 0){
                sb.append("-");
            }

        }
        return sb.reverse().toString().toUpperCase();

    }
}
